package DesignPattern.CommandPattern;
/**
 * @author : LdLtd
 * @Date : 2023/12/11
 * @Description:
 *  优点： 1、降低了系统耦合度。 2、新的命令可以很容易添加到系统中去。
 * 缺点：使用命令模式可能会导致某些系统有过多的具体命令类。
 */
public class Client {
    public static void main(String[] args) {
        Calculator calculator = new Calculator();

        // 创建命令对象
        Command addCommand = new AddCommand(calculator, 5);
        Command subtractCommand = new SubtractCommand(calculator, 3);
        Command multiplyCommand = new MultiplyCommand(calculator, 2);
        Command divideCommand = new DivideCommand(calculator, 4);


        //也可以没有broker
        Broker broker = new Broker();
        broker.takeCommand(addCommand);
        broker.takeCommand(subtractCommand);
        broker.takeCommand(multiplyCommand);
        broker.takeCommand(divideCommand);
        broker.placeCommand();



    /*    // 执行命令
        addCommand.execute();
        subtractCommand.execute();
        multiplyCommand.execute();
        divideCommand.execute();

        // 撤销命令
        divideCommand.undo();
        multiplyCommand.undo();
        subtractCommand.undo();
        addCommand.undo();*/
    }
}
